{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "59687c46",
   "metadata": {},
   "source": [
    "# 2022.09.21\n",
    "# python\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbd72c90",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "> 1. 数值（number）\n",
    ">> 1. 定义\n",
    ">> 2. 方法\n",
    "> 2. 字符串（string）\n",
    ">> 1. 定义\n",
    ">> 2. 方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ba91457",
   "metadata": {},
   "source": [
    "# 1.数值\n",
    "> 1. 对数值进行分类\n",
    ">> 1. 整数（int）\n",
    ">> 2. 浮点型（float）\n",
    ">> 3. 复数（complex）\n",
    "> 2. 数值的运算法则https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "6375aa4b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整数\n",
    "a=99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "8aacfe31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b=99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "a413efb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c=a+b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "9c2f8f50",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数(虚数)\n",
    "d=2+3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4bb11b1f",
   "metadata": {},
   "source": [
    "## 2.字符串（str）\n",
    "> 1. 定义\n",
    "> 2. 方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "774356e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name='Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "a00d447a",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can't multiply sequence by non-int of type 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-78-df8247c8ea27>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"18\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"22\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mb\u001b[0m          \u001b[1;31m#字符串不能运算\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'str'"
     ]
    }
   ],
   "source": [
    "a=\"18\"\n",
    "b=\"22\"\n",
    "a*b          #字符串不能运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "172f0bc2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a=18\n",
    "b=\"18\"\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "e4d8089e",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (<ipython-input-80-601c989a42c4>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-80-601c989a42c4>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    'dosen''t\u001b[0m\n\u001b[1;37m             ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "# 关于单引号和双引号\n",
    "'dosen''t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "0fb2c2a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"dosen't\""
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案1\n",
    "\"dosen't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "a5fbcf91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"dosen't\""
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案2  \\ 后面内容是“符号”，转义，\\ 自动消失\n",
    "'dosen\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "4db2b61a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# *正则表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "551bce5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包含任何文本\n",
    "# 作用：\n",
    "# 1.保持原数据的结构，包含符号，换行等。\n",
    "# 2.可以用来做代码注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "5d4f3aca",
   "metadata": {},
   "outputs": [],
   "source": [
    "NFU_招投标_HTML = \"\"\"\n",
    "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
    "    </a>\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "04dc7a4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
      "    </a>\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(NFU_招投标_HTML)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "a37e2431",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "### 三个引号来代码注释\n",
    "import random\n",
    "import time\n",
    "\n",
    "\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "页面后缀 = \".htm\"\n",
    "page = 5\n",
    "\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀)  # 字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)\n",
    "\"\"\"\n",
    "\n",
    "print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a969a868",
   "metadata": {},
   "source": [
    "### 2.1字符串的运算法则\n",
    "\n",
    "> 1. 字符串的拼接\n",
    "> 2. <font color=\"red\">字符串的有序性</font>\n",
    ">> 1. 取值\n",
    ">> 2. 切片\n",
    "> 3. enumerate:枚举\n",
    "> 4. in 可以查询成员对象是否存在\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "cad1d5d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'heloworld'"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串的拼接\n",
    "\"helo\"+ \"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "6d2435cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n",
      "你好，Marry\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text=\"你好，\"\n",
    "for i in [\"Alex\",\"Marry\"]:\n",
    "    result=text+i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "305ae627",
   "metadata": {},
   "source": [
    "* 取值\n",
    "> 1. 取单个值\n",
    "> 2. 切片，取连续多个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "24ab03bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "\n",
    "地址=\"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "2cab6990",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "fc85be09",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "dfdd8448",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "b6fde2e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "6caaf87f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "a314ef29",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广州 这个文本\n",
      "存在 广州 这个文本\n"
     ]
    }
   ],
   "source": [
    "# 实践：请检查 广州是否在 地址 里面？\n",
    "# 检查i[index]是否是广，然后判断i[index+i]下一个索引值的内容是否是州\n",
    "\n",
    "#方法   enumerate:枚举\n",
    "for index,value in enumerate(地址):\n",
    "    if value==\"广\":\n",
    "        if 地址[index+1]==\"州\":\n",
    "            print(\"存在 广州 这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "71891ff7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广院 这个文本\n"
     ]
    }
   ],
   "source": [
    "for index,value in enumerate(地址):\n",
    "    if value==\"广\":\n",
    "        if 地址[index-1]==\"院\":\n",
    "            print(\"存在 广院 这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "80981a30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法:in 可以查询成员变量的\n",
    "print(\"广州\"in 地址)\n",
    "print(\"Alex\"in 地址)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "e4f23e2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#字符串方法\n",
    "## 1. 首字母变大写\n",
    "## 2. 检查字符出现的次数\n",
    "\n",
    "print(\"alex\".capitalize())\n",
    "地址.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "938e1919",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
